<template>
  <a-select :getPopupContainer = "getPopupContainer" :placeholder="placeholder" :disabled="disabled" :value="getValueSting" @change="handleInput">
    <a-select-option :value="undefined">请选择</a-select-option>
    <a-select-option v-for="(item, key) in dictOptions" :key="key" :value="item.dictValue">
      <span style="display: inline-block;width: 100%" :title=" item.text || item.dictLabel ">
        {{ item.text || item.dictLabel }}
      </span>
    </a-select-option>
  </a-select>
</template>

<script>
  export default {
    name: "SSelect",
    props: {
      dictCode: String,
      placeholder: String,
      triggerChange: Boolean,
      disabled: Boolean,
      value: [String, Number],
      type: String,
      getPopupContainer:{
        type: Function,
        default: (node) => document.body
      }
    },
    data() {
      return {
        dictOptions: []
      }
    },
    watch:{
      dictCode:{
        immediate:true,
        handler() {
          this.initDictData()
        },
      }
    },
    created() {
    },
    computed: {
      getValueSting(){
        return this.value != null ? this.value.toString() : undefined;
      },
    },
    methods: {
      initDictData() {
        this.getDicts(this.dictCode, null).then((res) => {
          this.dictOptions = res.data
        })
      },
      handleInput(val) {
        this.$emit('input', val)
      },
      setCurrentDictOptions(dictOptions){
        this.dictOptions = dictOptions
      },
      getCurrentDictOptions(){
        return this.dictOptions
      }
    }
  }
</script>

<style scoped>
</style>